const app = getApp()
var netUtil = require("../../utils/netUtil.js"); //require引入
Page({
  data: {
    tabbar: {},
    nvabarData: {
      showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
      title: '首页', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height , 
    type:'dl',
    marginTop:'',
    userInfo: '',
    isTeacher:true,
    isService:true,
    isGzh: true,
    gzhImg:"https://sclyphxcx.ricecs.cn/img/public_img.jpg",
    isShare:true,
    token:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    this.setData({
      userInfo: wx.getStorageSync("userInfo")
    })
    console.log(this.data.userInfo)
    app.editTabbar();
    //判断在iphoneX和其它机型下头像位置
    if (app.globalData.isIpx===true){
      this.setData({
        marginTop:-30
      })
    }else{
      this.setData({
        marginTop: 20
      })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (!wx.getStorageSync("userInfo")) {
      wx.showModal({
        title: '提示',
        content: '您还未登录，请先登录',
        success(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/author/author',
            })
          } else if (res.cancel) {
            wx.switchTab({
              url: '/pages/index/index',
            })
          }
        }
      })
      
    }
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4
      })
    }
    this.setData({
      userInfo: wx.getStorageSync("userInfo"),
      token:wx.getStorageSync("token")
    })
    this.getUser();
    this.getTeacher();
  
  },
  dlApply(){
    wx.navigateTo({
      url: '/pages/dlApply/dlApply',
    })
  },
  // 提现列表
  toWithdrawalList(){
    wx.navigateTo({
      url: '/pages/withdrawalList/withdrawalList',
    })
  },
 // 获取教务老师
 getTeacher(){
  netUtil.postData('user/getTeacher',{token:this.data.token}, (datas) => {
    if(datas.code===1){
      this.setData({
        teacher: datas.data.teacher
      })
    }   
  })
},
hideteacher(){
  this.setData({
    isTeacher:true
  })
},
  // 获取用户信息
  getUser(){
    let params={
      token: this.data.token
    }
    netUtil.postData('user/load', params, (datas) => {
        wx.setStorageSync("userInfo",datas.data.model)
        this.setData({
          userInfo:datas.data.model
        })
    })
  },
  // 提现
  withdraw(){
    wx.navigateTo({
      url: '/pages/withdraw/withdraw',
    })
  },
  // 点击显示教务老师
  teacher(){
    this.setData({
      isTeacher:false
    })
  },
  // 点击隐藏教务老师
  teacherHide(){
    this.setData({
      isTeacher: true
    })
  },
  // 保存二维码
  gotoSaveImg() {
    var that = this;
    console.log(that.data.teacher.wx_qrcode)
    wx.downloadFile({
      url: that.data.teacher.wx_qrcode,
      success: function (res) {     
        console.log(res);
        //图片保存到本地
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function (data) {
            wx.showToast({
              title: '保存成功',
              icon: 'success',
              duration: 2000
            })
            that.setData({
              isTeacher: true
            })
          },
          fail: function (err) {
            that.setData({
              isTeacher: true
            })
          },
          complete(res) {
            console.log(res);
          }
        })
      }
    })
  },
   // 我的分享
   myShare(){
    if (!wx.getStorageSync("userInfo").mobile){   
      wx.showToast({
        title: '请授权手机号',
        icon:'none'
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/pages/getTel/getTel',
        })
      },1000)
      return
    }
    wx.navigateTo({
      url: '/pages/myShare/myShare?type=wdfx',
    })
  },
  toCoupon(){
    wx.navigateTo({
      url: '/pages/coupon/coupon',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  
 
  ptShare(){
    wx.navigateTo({
      url: '/pages/myShare/myShare?type=wdfx',
    })
  },
  dlShare(){
    wx.navigateTo({
      url: '/pages/myShare/myShare?type=dl',
    })
  },
  shareHide(){
    this.setData({
      isShare: true
    })
  },
  // 实名认证
  realName(){
    wx.navigateTo({
      url: '/pages/realName/realName',
    })
  },
  // 待付款、分期中、已逾期、已完成跳转
  orderList(e){  
    wx.navigateTo({
      url: '/pages/orderList/orderList?type=' + e.currentTarget.dataset.type,
    })
  },
  // 我的订单跳转
  myOrder(){
    
    wx.navigateTo({
      url: '/pages/bill/bill',
    })
  },
  // 我的粉丝跳转
  myFans(){
    wx.navigateTo({
      url: '/pages/myFans/myFans',
    })
  },
 
  
  
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})